package cn.schoolwow.quickdao.test.module.business.user.dml.user.flow.edit.option;

import cn.schoolwow.quickdao.domain.DAO;
import cn.schoolwow.quickdao.test.entity.User;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.instanceList.QueryInstanceList;
import org.junit.Assert;

import java.util.List;

public class CheckPasswordPartColumnUpdateResultFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        DAO dao = flowContext.checkInstanceData(DAO.class);
        List<User> insertUserList = (List<User>) flowContext.checkData("insertUserList");

        List<Long> idList = QueryInstanceList.newQuery(insertUserList)
                .execute()
                .getSingleFieldValueList("id");
        List<User> userList = dao.query(User.class)
                .addInQuery("id", idList)
                .execute()
                .getList();
        for(User user:userList){
            User insertUser = QueryInstanceList.newQuery(insertUserList)
                    .addQuery("id", user.getId())
                    .execute()
                    .getOne();
            Assert.assertNotNull(insertUser);
            Assert.assertEquals(insertUser.getPassword(), user.getPassword());
            Assert.assertNotEquals(insertUser.getMobile(), user.getMobile());
        }
    }

    @Override
    public String name() {
        return "检查仅更新密码流程结果";
    }
}
